package com.example.wenhua.utils;

/**
 * 角色工具类
 * 用于处理角色相关的转换和验证
 */
public class RoleUtil {
    
    // 角色常量
    public static final Integer ADMINISTRATOR = 0;
    public static final Integer TEACHER = 1;
    public static final Integer STUDENT = 2;
    
    // 角色名称常量
    public static final String ADMINISTRATOR_NAME = "Administrator";
    public static final String TEACHER_NAME = "Teacher";
    public static final String STUDENT_NAME = "Student";
    
    /**
     * 将数字角色转换为字符串角色名称
     * @param role 数字角色 (0=管理员, 1=教师, 2=学生)
     * @return 角色名称字符串
     */
    public static String getRoleName(Integer role) {
        if (role == null) {
            return null;
        }
        
        switch (role) {
            case 0:
                return ADMINISTRATOR_NAME;
            case 1:
                return TEACHER_NAME;
            case 2:
                return STUDENT_NAME;
            default:
                return "Unknown";
        }
    }
    
    /**
     * 将字符串角色名称转换为数字角色
     * @param roleName 角色名称字符串
     * @return 数字角色
     */
    public static Integer getRoleValue(String roleName) {
        if (roleName == null) {
            return null;
        }
        
        switch (roleName) {
            case ADMINISTRATOR_NAME:
                return ADMINISTRATOR;
            case TEACHER_NAME:
                return TEACHER;
            case STUDENT_NAME:
                return STUDENT;
            default:
                return null;
        }
    }
    
    /**
     * 检查角色权限
     * 管理员(0) > 教师(1) > 学生(2)
     * @param userRole 用户角色
     * @param requiredRole 需要的角色
     * @return 是否有权限
     */
    public static boolean hasPermission(Integer userRole, Integer requiredRole) {
        if (userRole == null || requiredRole == null) {
            return false;
        }
        
        // 数字越小权限越高
        return userRole <= requiredRole;
    }
}